home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / arcii2.arc / ASCII.C next >
Text File  |  1985-11-28  |  5KB  |  124 lines

  1. /*  ASCII - Show ASCII text in a file.
  2.  
  3.     Version 1.15, created on 03/07/85 at 00:15:43
  4.  
  5.     BY: Thom Henderson
  6.  
  7. (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  8.  
  9.     DESCRIPTION:
  10.          This program prints a list of all ASCII text in a file.  It
  11.          can be used to, among other things, show all text messages
  12.          in an .EXE or .COM file.
  13.  
  14.     INSTRUCTIONS:
  15.          Run this program with no arguments for complete instructions.
  16.  
  17.     LANGUAGE:
  18.          Computer Innovations Optimizing C86
  19. */
  20. #include <stdio.h>
  21.  
  22. main(num,arg)                          /* system entry point */
  23. int num;                               /* number of arguments */
  24. char *arg[];                           /* pointers to arguments */
  25. {
  26.     FILE *f, *fopen();                 /* file to scan, opener */
  27.     int c;                             /* one character from file */
  28.     long loc = 0;                      /* location in file */
  29.     int len = 0;                       /* length of string so far */
  30.     int wid = 0;                       /* width of output so far */
  31.     char buf[79];                 /* output buffer */
  32.     char *b = buf;                     /* output buffer pointer */
  33.     char *upper();                     /* case converter */
  34.  
  35.     if(num<2)                          /* no args - give help */
  36.     {    printf("ASCII, Version 1.15, created on 03/07/85 at 00:15:43\n");
  37.          printf("(C) Copyright 1985 by System Enhancement Associates;");
  38.          printf(" ALL RIGHTS RESERVED\n\n");
  39.  
  40.          printf("You are granted a license to use this product for a");
  41.          printf(" period of TWO WEEKS.\n");
  42.          printf("If you wish to continue using this product once your");
  43.          printf(" two week trial period\n");
  44.          printf("is up, then you must send twenty dollars ($20) to:\n\n");
  45.  
  46.          printf("    System Enhancement Associates\n");
  47.          printf("    12 Franklin Avenue\n");
  48.          printf("    Clifton, NJ  07011\n\n");
  49.  
  50.          printf("You are also encouraged to freely copy and distribute");
  51.          printf(" this product,\n");
  52.          printf("provided that no fee is charged for said copying");
  53.          printf(" and/or distribution, and\n");
  54.          printf("provided that it is distributed ONLY in its original,");
  55.          printf(" unmodified form.\n\n\n");
  56.  
  57.          printf("Usage: ascii <filename>\n\n");
  58.          printf("Where <filename> is any valid DOS 2.0+ path name.\n");
  59.          return(1);
  60.     }
  61.  
  62.     f = fopen(arg[1],"rb");
  63.     if(!f)
  64.          abort("Unable to read %s",upper(arg[1]));
  65.  
  66.     while(!feof(f))
  67.     {    c = fgetc(f);                 /* get a character */
  68.  
  69.          if(c=isascii(c))              /* if ASCII text */
  70.          {    if(!wid)                 /* if start of a line */
  71.               {    sprintf(buf,"%lx: ",loc);
  72.                    while(*b++)         /* find end/length of address */
  73.                         wid++;
  74.                    b--;
  75.               }
  76.               *b++ = c;                /* save the text character */
  77.               len++; wid++;            /* update length/width */
  78.  
  79.               if(wid>=79)         /* if at edge of screen */
  80.               {    *b = '\0';          /* terminate the text */
  81.                    printf("%s\n",buf); /* dump the buffer */
  82.                    b = buf;            /* restart buffer */
  83.                    wid = 0;
  84.               }
  85.          }
  86.  
  87.          else                          /* not ASCII text */
  88.          {    if(len>4 && wid)    /* if enough to print */
  89.               {    *b = '\0';          /* then terminate the buffer */
  90.                    printf("%s\n",buf); /* and dump it */
  91.               }
  92.               b = buf;                 /* restart the buffer */
  93.               len = wid = 0;
  94.          }
  95.  
  96.          loc += 1;                     /* update file location */
  97.     }
  98.  
  99.     if(len>4 && wid)              /* if anything was left hanging */
  100.     {    *b = '\0';                    /* then terminate the buffer */
  101.          printf("%s\n",buf);           /* and dump it */
  102.     }
  103.  
  104.     makefnam("X;\\",arg[1],buf);       /* get name with fixed path */
  105.     b = buf + 3;                       /* point to name without path */
  106.     printf("\nLength (%s) = %lx hex\n",upper(b),loc);
  107.  
  108.     return 0;
  109. }
  110.  
  111. int isascii(c)                         /* test and map characters */
  112. int c;                                 /* character to test */
  113. {
  114.     if(isprint(c))                     /* if printable */
  115.          return c;                     /* then that is that */
  116.     if(c=='\r')                        /* return */
  117.          return 27;                    /* map to left arrow */
  118.     if(c=='\n')                        /* linefeed */
  119.          return 24;                    /* map to uparrow */
  120.     if(c=='\t')                        /* tab */
  121.          return 26;                    /* map to right arrow */
  122.     return 0;                          /* that's all for now */
  123. }
  124.